package com.icss.th.question.facade.mysql;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.UUID;

import com.icss.th.common.exception.ThException;
import com.icss.th.common.util.DateUtil;
import com.icss.th.db.DBConnection;
import com.icss.th.db.sql.SqlText;
import com.icss.th.question.facade.IOptionFacade;

public class OptionFacadeMysql implements IOptionFacade 
{	
	@Override
	public void saveExplain(String content, String examId, String ip) throws ThException 
	{	
		Connection conn = DBConnection.getConnection();
		PreparedStatement ps = null;
		
		try
		{
			try
			{
				ps = conn.prepareStatement(SqlText.GET_SAVEEXPLAIN_SQL);
				ps = conn.prepareStatement(SqlText.GET_SAVEEXPLAIN_SQL);
				ps.setString(1, UUID.randomUUID().toString());
				ps.setInt(2, Integer.valueOf(examId));
				ps.setString(3, ip);
				ps.setString(4, content);
				ps.setDate(5, DateUtil.getCurrentDate());
				ps.execute();
			}
			finally
			{
				ps.close();
			}
		}
		catch (SQLException e)
		{
			throw new ThException(e.getMessage(), e);
		}
	}

	@Override
	public void saveCorrect(String content, String examId,
			String optionType, String ip) throws ThException 
	{
		Connection conn = DBConnection.getConnection();
		PreparedStatement ps = null;
		
		try
		{
			try
			{
				ps = conn.prepareStatement(SqlText.GET_SAVECORRECT_ID);
				ps.setString(1, UUID.randomUUID().toString());
				ps.setInt(2, Integer.valueOf(examId));
				ps.setString(3, ip);
				ps.setString(4, content);
				ps.setString(5, optionType);
				ps.setDate(6, DateUtil.getCurrentDate());
				ps.execute();
			}
			finally
			{
				ps.close();
			}
		}
		catch(SQLException e)
		{
			throw new ThException(e.getMessage(), e);
		}
	}
}
